<template>
  <div>
    <div class="card-box-2 mt20" @click="goFile">
      <!-- 标题 -->
      <div class="title-box">
        <div class="title" v-html="highlightText(item.fileName)"></div>
      </div>
      <!-- 详情 -->
      <div class="detail-box">
        <!-- <img
          class="image"
          v-if="item.type === 'pdf'"
          src="@/assets/img/word.png"
          alt=""
        /> -->
        <div class="attr-box">
          <span class="detail" v-html="highlightText(item.content)"></span>
        </div>
        <div
          class="image-box"
          v-if="
            item.type === 'png' || item.type === 'jpg' || item.type === 'jpeg'
          "
        >
          <img :src="item.fileUrl" alt="" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      searchKey: "",
    };
  },
  methods: {
    setData(val) {
      this.searchKey = val;
    },
    // 高亮文字
    highlightText(text) {
      if (!text) return;
      return text.replace(
        new RegExp(this.searchKey, "g"),
        `<span style="color: #FF5151">${this.searchKey}</span>`
      );
    },
    goFile() {
      let pdfUrl = this.item.fileUrl;
      console.log(9999, pdfUrl);
      window.open(pdfUrl, "_blank");
    },
  },
};
</script>

<style lang="scss" scoped>
.card-box-2 {
  width: 100%;
}
.title-box {
  display: flex;
  align-items: center;
  margin-bottom: 14px;
  .title {
    font-size: 22px;
    color: #ffffff;
  }
}
.detail-box {
  display: flex;
  align-items: flex-start;
  font-size: 14px;
  line-height: 2;
  width: 100%;
  .attr-box {
    .detail {
      color: #ffffff;
      font-size: 20px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .image {
    image-rendering: pixelated;
    height: 112px;
    // max-width: 200px;
    margin-right: 20px;
  }
  .image-box {
    width: 100%;
    img {
      width: 100%;
    }
  }
}
</style>
